﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;
namespace Server_NhaSach.DataAccess.LogicLayer
{
    public class KhoDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion

        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion

        #region "Khai báo các Method"
        public bool InserKho(KhoDTO Kho)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[3];
            par[0] = new SqlParameter("@MaKho", Kho.MaKho);
            par[1] = new SqlParameter("@TenKho", Kho.TenKho);
            par[2] = new SqlParameter("@TongSoLuongTon", Kho.Tongsoluongton);
            try
            {
                helper.InsertQuery("sp_Insert_Kho", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdateKho(KhoDTO Kho)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[3];
            par[0] = new SqlParameter("@MaKho", Kho.MaKho);
            par[1] = new SqlParameter("@TenKho", Kho.TenKho);
            par[2] = new SqlParameter("@TongSoLuongTon", Kho.Tongsoluongton);
            try
            {
                helper.UpdateQuery("sp_Update_Kho", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeletKho(string maKho)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@maKho", maKho);
            try
            {
                helper.DeleteQuery("sp_Delete_Kho", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_Kho()
        {
            helper = new Helper();
            DataSet ds_Kho = helper.SelectQuery("sp_LayDS_Kho");
            return ds_Kho;
        }
        #endregion
    }
}